package top.jolyoulu.business.web.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.jolyoulu.modules.redismodule.lock.KeyRule;
import top.jolyoulu.modules.redismodule.lock.KeyRuleManager;

import java.util.UUID;

/**
 * @Author LuZhouJin
 * @Date 2023/5/31
 */
@Configuration
public class KetRuleConfig {

    @Autowired
    private KeyRuleManager keyRuleManager;

    @Bean
    public void TestKeyRule(){
        keyRuleManager.add(new TestKeyRule());
    }

    public static class TestKeyRule implements KeyRule {

        @Override
        public String getKey(String arg) {
            return "TestKeyRule:" + arg + ":" + UUID.randomUUID().toString();
        }

        @Override
        public void LockFailure() {
            throw new RuntimeException("TestKeyRule");
        }
    }
}
